package com.lbb.simple.demo.activity

import android.os.Bundle
import android.view.View
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.PagerSnapHelper
import androidx.viewpager.widget.ViewPager

import com.lbb.simple.databinding.ActivityMainBinding
import com.lbb.simple.demo.adapter.BannerAdapter
import com.lbb.simple.demo.bean.Banner
import com.lbb.simple.demo.controller.BannerController
import com.lbb.simple.demo.fragment.CourseFragment
import com.lbb.simple.demo.fragment.FmFragment
import com.lbb.simple.demo.widget.tab.bottom.Adapter
import com.lbb.utils.FragmentAdapter
import com.lbb.utils.recycler.BaseStateAdapter
import com.lbb.utils.recycler.RecyclerListener


class MainActivity : BaseActivity<ActivityMainBinding>() {
    //    private val bannerAdapter = BannerAdapter()
//    private val bannerPresenter = BannerController.BannerPresenter(this)

    private val list = listOf(CourseFragment(), FmFragment())
    private val bottomAdapter = Adapter()
    override fun getLayoutContent(): ActivityMainBinding {
        return ActivityMainBinding.inflate(layoutInflater)
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
//        b.recyclerView.adapter = bannerAdapter
//        b.recyclerView.layoutManager = LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false)
//        PagerSnapHelper().attachToRecyclerView(b.recyclerView)
//        bannerAdapter.onClickErrorListener= RecyclerListener.OnClickErrorListener { bannerPresenter.getBanner(1) }
        b.viewPager.adapter = FragmentAdapter(supportFragmentManager, list)
        b.recyclerView.layoutManager = GridLayoutManager(this, 5)
        b.recyclerView.adapter = bottomAdapter
        bottomAdapter.onClickListener = RecyclerListener.OnClickListener { _, _, position ->
            bottomAdapter.setPosition(position)
            b.viewPager.setCurrentItem(position, true)
        }
        b.viewPager.addOnPageChangeListener(object :ViewPager.OnPageChangeListener{
            override fun onPageScrolled(
                position: Int,
                positionOffset: Float,
                positionOffsetPixels: Int
            ) {

            }

            override fun onPageSelected(position: Int) {
                bottomAdapter.setPosition(position)
            }

            override fun onPageScrollStateChanged(state: Int) {

            }
        })
    }


}